<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>产品分类</title>
</head>
<body>
<script>
    $(function () {
        $("tboby tr").addClass("datagrid-row");
        $("#pcdg").datagrid({
            onLoadSuccess:function (data) {
                $("a[name='details']").linkbutton({
                    width:30,iconCls:'icon-my_detail',plain:true
                });
                $("a[name='delete-one-proc']").linkbutton({
                    onClick: function () {
                        var rowId = $(this).attr("id").substring(5);
                        $.messager.confirm("继续删除提示", "确定要删除选定的分类吗？" +
                            "\n如果删除的分类有子分类则会同时删除所有子分类并将分类下的产品分类信息置空！", function (a) {
                            if (a) {
                                $.post("pro-categorys-del", {rowsId: rowId}, function (r) {
                                    if (r.success) {
                                        $.messager.alert("SUCCESS", "删除成功！", "info");
                                        $("#pcdg").datagrid({
                                            url:'allProCategories',
                                            method:'post'
                                        });
                                        $("#pcdg").datagrid("reload");
                                    } else {
                                        $.messager.alert("Failed", r.message, "error");
                                    }
                                });
                            }
                        });
                    },
                    width: 30, iconCls: 'icon-my_delete', plain: true
                });
                $("a[name='edit']").linkbutton({
                    width:30,iconCls:'icon-my_edit',plain:true
                });
            }
        });
        //重载所有的产品分类
        $("#reloadAllProC").linkbutton({
            onClick:function () {
                $("#pcdg").datagrid({
                    url:'allProCategories',
                    method:'post'
                });
                $("#pcdg").datagrid("reload");
            }
        });

        //删除选中的分类(批量删除)
        $("#pro-categorys-del-btn").linkbutton({onClick:function (){
                var rowsId = "";
                var rows = $("#pcdg").datagrid('getSelections');
            if(rows.length>=1){
                $.messager.confirm("继续删除提示","确定要删除选定的分类吗？" +
                    "\n如果删除的分类有子分类则会同时删除所有子分类并将分类下的产品分类信息置空！",function (t) {
                    if(t){
                            for(var i =0; i<rows.length;i++){
                                if(i==0){
                                    rowsId=rowsId+rows[i].pcid;
                                }else {
                                    rowsId=rowsId+","+rows[i].pcid;
                                }

                            }
                            $.post("pro-categorys-del",{rowsId:rowsId},function (r) {
                                if(r.success){
                                    $.messager.alert("SUCCESS","删除成功！","info");
                                    $("#pcdg").datagrid({
                                        url:'allProCategories',
                                        method:'post'
                                    });
                                    $("#pcdg").datagrid("reload");
                                }else{
                                    $.messager.alert("Failed",r.message,"error");
                                }
                            });
                        }
            });

            }else{
                $.messager.alert("错误信息","未选中行！！！",'warning');
            }
        }});
    });
    function format(value,row,index){
        var str='<a id = \"'+"pcShow"+row.pcid+'\" name="details" href="#" onclick="createDialogHut(\'detilsProC'+row.pcid+'\',\'分类详情\',\'to-form-proC-details\','+row.pcid+')" class="easyui-linkbutton edit-btn"></a>'+
            '<a id =\"'+"pcDel"+row.pcid+'\" name="delete-one-proc" href="#"  class="easyui-linkbutton edit-btn"></a>'+
            '<a id = \"'+"pcUpdate"+row.pcid+'\" name="edit" href="#" onclick="createDialogHut(\'editProC'+row.pcid+'\',\'修改分类信息\',\'to-form-proC-update\','+row.pcid+')" class="easyui-linkbutton edit-btn"></a>';
        return str;
    }
    function formatD(value,row,index) {
        return '<span style="font-size:12px;color:mediumvioletred;">'+value+'级分类</span>';
    }

</script>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false">
        <table id="pcdg" class="easyui-datagrid table-chance" style="width: auto;" data-options="fit:true,striped:true,height:350,fitColumns:true,
   autoRowHeight:true,nowrap:false,pagination:true,toolbar:'#tools-productionC',
pageList:[5,10,15,20],pageSize:10,url:'allProCategories',method:'post',scrollbarSize:0">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'code',width:10,align:'center',checkbox:true">编码</th>
                <th data-options="field:'pcid',width:60,align:'center'">分类ID</th>
                <th data-options="field:'pcname',width:100,align:'center'">分类名称</th>
                <th data-options="field:'pcdepth',width:100,align:'center'" formatter="formatD">分类深度</th>
                <th data-options="field:'pcpid',width:60,align:'center',hidden:true">父分类ID</th>
                <th data-options="field:'pcpname',width:60,align:'center'">父分类名称</th>
                <th data-options="field:'pcpriority',width:60,align:'center'">分类优先级</th>
                <th data-options="field:'manager',width:100,align:'center'" formatter="format">操作</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--工具栏-->
        <div id="tools-productionC" style="height:10%;">
            <a href="#" onclick="createDialog('newProC','新建产品分类','to-form-proC')" class="easyui-linkbutton"data-options="iconCls:'icon-mini_add2',plain:true">新建</a>
            <a href="#" id="pro-categorys-del-btn" class="easyui-linkbutton" data-options="iconCls:'icon-my_delete',plain:true">批量删除</a>
            <a  id="reloadAllProC" class="easyui-linkbutton" data-options="iconCls:'icon-my_search',plain:true">查询所有</a>

            <input id="ProC-Search" class="easyui-searchbox" style="width: 30%;" data-options="searcher:function(value,name){
            $('#pcdg').datagrid({
            url:'getAllCategoryBymh',
            method:'post',
            queryParams:{q:value}
            });
            $('#ProC-Search').searchbox('clear');
            $('#pcdg').datagrid('reload');
           },prompt:'模糊查询分类名或分类id'"/>
            <a href="#" onclick="createDialog('hlQueryProC','高级查询产品分类','to-form-proC-highLevel')" class="easyui-linkbutton">高级查询</a>
        </div>
    </div>
</div>
</body>
</html>

